package dao;

import java.util.ArrayList;
import java.util.List;

import model.*;

public class MachineTypeDao {
	private List<MachineType> machineTypes = new ArrayList<MachineType>();

	private static MachineTypeDao instance = null;

	public MachineTypeDao() {

	}

	/**
	 * This is a static method that return new machineTypeDao when instance is
	 * null
	 * 
	 * @author Osahon Idehen
	 */

	public static MachineTypeDao getInstance() {
		if (instance == null)
			instance = new MachineTypeDao();
		return instance;
	}

	/**
	 * This adds a MachineTypes
	 * 
	 * @author Osahon Idehen
	 */

	public void addMachineType(MachineType machineType) {
		if (!machineTypes.contains(machineType)) {
			machineTypes.add(machineType);
		}
	}

	/**
	 * This removes a MachineType
	 * 
	 * @author Osahon Idehen
	 */

	public void removeMachineType(MachineType machineType) {
		if (machineTypes.contains(machineTypes)) {
			machineTypes.remove(machineType);
		}
	}

	/**
	 * This returns machineTypes from the list
	 * 
	 * @author Osahon Idehen
	 */
	public List<MachineType> getMachineTypes() {
		return machineTypes;
	}

	// TODO extra methods

	/**
	 * Gets all the Machines from all the MachineTypes.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public List<Machine> getMachines() {
		List<Machine> machineList = new ArrayList<Machine>();
		for (MachineType mt : machineTypes) {
			machineList.addAll(mt.getMachines());
		}
		return machineList;
	}

	/**
	 * Gets all the Reparations from all the Machines.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public List<Reparation> getReparations() {
		List<Reparation> repList = new ArrayList<Reparation>();
		for (Machine r : getMachines()) {
			repList.addAll(r.getReparations());
		}
		return repList;
	}

	/**
	 * Gets all the RepairTypes from all the Machines.
	 * 
	 * @author Csaba Tarkanyi
	 */
	public List<RepairType> getRepairTypes() {
		List<RepairType> reptList = new ArrayList<RepairType>();
		for (MachineType mt : machineTypes) {
			reptList.addAll(mt.getRepairTypes());
		}
		return reptList;
	}

	// TODO extra methods
}
